package blazingbubble.network.game;

import blazingbubble.network.game.strategy.*;
import blazingbubble.game.command.net.NetGameCommandFactory;
import moltencore.network.protocol.PlayerJoinedGame;
import moltencore.network.protocol.TimeLeft;
import spark.network.strategy.IProtocolHandleStrategy;

public class GameStrategyFactory {
	private IJoinGameResponseResultListener joinGameResponseResultListener;
	private IPlayerTeamJoinListener playerTeamJoinListener;
	private blazingbubble.game.Game game;
	private NetGameCommandFactory netGameCommandFactory;
	private PlayerTeamJoinBuffer playerTeamJoinBuffer = new PlayerTeamJoinBuffer();

	private JoinGameResponseStrategy joinGameResponse;
	private StartGameResponseStrategy startGameResponse;
	private GameStartingNotificationStrategy gameStartingNotificationStrategy;
	private FieldLayoutStrategy fieldLayoutStrategy;
	private GameStartedStrategy gameStartedStrategy;
	private CannonNewTargetDirectionStrategy cannonNewTargetDirectionStrategy;
	private BubbleFixatedNotificationStrategy bubbleFixatedNotificationStrategy;
	private BubblePoppedNotificationStrategy bubblePoppedNotificationStrategy;
	private BubbleNextNotificationStrategy bubbleNextNotificationStrategy;
	private BubbleMovingNotificationStrategy bubbleMovingNotificationStrategy;
	private PlayerJoinedGameStrategy playerJoinedGameStrategy;
	private PlayerJoinedTeamStrategy playerJoinedTeamStrategy;
	private PlayerScoreUpdateStrategy playerScoreUpdateStrategy;
	private GameEndedNotificationStrategy gameEndedNotificationStrategy;
	private RowPushedStrategy rowPushedStrategy;
	private TimeLeftStrategy timeLeftStrategy;

	public GameStrategyFactory(
			IJoinGameResponseResultListener joinGameResponseResultListener,
			IPlayerTeamJoinListener playerTeamJoinListener,
			blazingbubble.game.Game game,
			NetGameCommandFactory netGameCommandFactory) {
		this.joinGameResponseResultListener = joinGameResponseResultListener;
		this.playerTeamJoinListener = playerTeamJoinListener;
		this.game = game;
		this.netGameCommandFactory = netGameCommandFactory;
	}

	public JoinGameResponseStrategy getJoinGameResponseStrategy() {
		if(joinGameResponse == null) {
			joinGameResponse = new JoinGameResponseStrategy(joinGameResponseResultListener, game);
		}
		return joinGameResponse;
	}

	public StartGameResponseStrategy getStartGameResponseStrategy() {
		if(startGameResponse == null) {
			startGameResponse = new StartGameResponseStrategy();
		}
		return startGameResponse;
	}

	public GameStartingNotificationStrategy getGameStartingNotificationStrategy() {
		if(gameStartingNotificationStrategy == null) {
			gameStartingNotificationStrategy = new GameStartingNotificationStrategy(game, netGameCommandFactory);
		}
		return gameStartingNotificationStrategy;
	}

	public FieldLayoutStrategy getFieldLayoutStrategy() {
		if(fieldLayoutStrategy == null) {
			fieldLayoutStrategy = new FieldLayoutStrategy(game, netGameCommandFactory);
		}
		return fieldLayoutStrategy;
	}

	public GameStartedStrategy getGameStartedStrategy() {
		if(gameStartedStrategy == null) {
			gameStartedStrategy = new GameStartedStrategy();
		}
		return gameStartedStrategy;
	}

	public CannonNewTargetDirectionStrategy getCannonNewTargetDirectionStrategy() {
		if(cannonNewTargetDirectionStrategy == null) {
			cannonNewTargetDirectionStrategy = new CannonNewTargetDirectionStrategy(game);
		}
		return cannonNewTargetDirectionStrategy;
	}

	public BubbleFixatedNotificationStrategy getBubbleFixatedNotificationStrategy() {
		if(bubbleFixatedNotificationStrategy == null) {
			bubbleFixatedNotificationStrategy = new BubbleFixatedNotificationStrategy(game);
		}
		return bubbleFixatedNotificationStrategy;
	}

	public BubblePoppedNotificationStrategy getBubblePoppedNotificationStrategy() {
		if(bubblePoppedNotificationStrategy == null) {
			bubblePoppedNotificationStrategy = new BubblePoppedNotificationStrategy(game);
		}
		return bubblePoppedNotificationStrategy;
	}

	public BubbleNextNotificationStrategy getBubbleNextNotificationStrategy() {
		if(bubbleNextNotificationStrategy == null) {
			bubbleNextNotificationStrategy = new BubbleNextNotificationStrategy(game);
		}
		return bubbleNextNotificationStrategy;
	}

	public BubbleMovingNotificationStrategy getBubbleFiredNotificationStrategy() {
		if(bubbleMovingNotificationStrategy == null) {
			bubbleMovingNotificationStrategy = new BubbleMovingNotificationStrategy(game);
		}
		return bubbleMovingNotificationStrategy;
	}

	public PlayerJoinedGameStrategy getPlayerJoinedGameStrategy() {
		if(playerJoinedGameStrategy == null) {
			playerJoinedGameStrategy = new PlayerJoinedGameStrategy(game, playerTeamJoinListener, playerTeamJoinBuffer);
		}
		return playerJoinedGameStrategy;
	}

	public PlayerJoinedTeamStrategy getPlayerJoinedTeamStrategy() {
		if(playerJoinedTeamStrategy == null) {
			playerJoinedTeamStrategy = new PlayerJoinedTeamStrategy(game, playerTeamJoinListener, playerTeamJoinBuffer);
		}
		return playerJoinedTeamStrategy;
	}

	public PlayerScoreUpdateStrategy getPlayerScoreUpdateStrategy() {
		if(playerScoreUpdateStrategy == null) {
			playerScoreUpdateStrategy = new PlayerScoreUpdateStrategy(game);
		}
		return playerScoreUpdateStrategy;
	}

	public GameEndedNotificationStrategy getGameEndedNotificationStrategy() {
		if(gameEndedNotificationStrategy == null) {
			gameEndedNotificationStrategy = new GameEndedNotificationStrategy(game);
		}
		return gameEndedNotificationStrategy;
	}

	public RowPushedStrategy getRowPushedStrategy() {
		if(rowPushedStrategy == null) {
			rowPushedStrategy = new RowPushedStrategy(game);
		}
		return rowPushedStrategy;
	}

	public IProtocolHandleStrategy<TimeLeft> getTimeLeftStrategy() {
		if(timeLeftStrategy == null) {
			timeLeftStrategy = new TimeLeftStrategy(game);
		}
		return timeLeftStrategy;
	}
}